<!DOCTYPE html>
<html lang="zh_CN">

<head>
   <#include "../common/header.ftl">

    <script>
        $(function () {
            //游记状态的修改 发布 和拒绝
            $(".stateBtn").click(function () {
                //获取按钮上的状态
                var state = $(this).data("state");
                //获取按钮上的id
                var id = $(this).data("id");

                $.get("/travel/changeState.do",{"state":state,"id":id},function (data) {
                    if(data.success){
                        window.location.reload();
                    }
                })
            })
            //游记内容的查看
            $(".showContent").click(function () {
                //获取按钮上的id
                var id = $(this).data("id");
                $.get("/travel/getTravelContent.do",{"travelId":id},function (data) {
                    console.log(data);
                    //把获取到的游记内容拼接到模态框中
                    $("#showContentModal .modal-body").html(data.content);
                    $("#showContentModal").modal('show');

                })
            })

            //游记的推荐
            $(".commendBtn").click(function () {
                $("#editForm").clearForm(true);

                var json = $(this).data("json");
                console.log(json);
                if(json){

                    $("#editForm input[name='title']").val(json.title);
                    $("#editForm input[name='travel.id']").val(json.id);
                    $("#editForm input[name='coverUrl']").val(json.coverUrl);
                    $("#editForm img").attr("src",json.coverUrl)
                }

                $("#inputModal").modal("show");
            })

            //推荐保存
            $(".saveBtn").click(function () {
                $("#editForm").ajaxSubmit(function (data) {
                    if(data.success){
                        window.location.reload();
                    }
                })
            })
        })
    </script>
    <!--设置模态框的样式-->
    <style>
        #showContentModal img{
            width: 100%;
        }
        #showContentModal .modal-body{
            max-height: 500px;
            overflow-y: auto;
        }

    </style>
</head>

<body>

<!--游记内容-->
<div class="modal fade" id="showContentModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
    <div class="modal-dialog" role="document">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span
                        aria-hidden="true">&times;</span></button>
                <h4 class="modal-title" id="myModalLabel">游记的内容</h4>
            </div>
            <div class="modal-body">

            </div>
        </div>
    </div>
</div>

<!--游记攻略模态框-->
<div class="modal fade" id="inputModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
    <div class="modal-dialog" role="document">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span
                        aria-hidden="true">&times;</span></button>
                <h4 class="modal-title" id="myModalLabel">编辑/添加</h4>
            </div>
            <div class="modal-body">

                <form class="form-horizontal" action="/travelCommend/saveOrUpdate.do" method="post"
                      id="editForm" enctype="multipart/form-data">
                    <input type="hidden" name="id">
                    <input type="hidden" name="travel.id">
                    <div class="form-group">
                        <label class="col-sm-4 control-label">标题:</label>
                        <div class="col-sm-6">
                            <input type="text" class="form-control" name="title">
                        </div>
                    </div>

                    <div class="form-group">
                        <label class="col-sm-4 control-label">副标题：</label>
                        <div class="col-sm-6">
                            <input type="text" class="form-control" name="subTitle">
                        </div>
                    </div>

                    <div class="form-group">
                        <label class="col-sm-4 control-label">封面：</label>
                        <div class="col-sm-6">
                            <img src="#" width="100px">
                            <input type="hidden" class="form-control" name="coverUrl">
                            <input type="file" class="form-control" name="pic">
                        </div>
                    </div>

                    <div class="form-group">
                        <label class="col-sm-4 control-label">推荐时间：</label>
                        <div class="col-sm-6">
                            <input type="text" class="form-control" name="schedule" onclick="WdatePicker()">
                        </div>
                    </div>



                    <div class="form-group">
                        <label class="col-sm-4 control-label">推荐类型：</label>
                        <div class="col-sm-6">
                            <select class="form-control" name="type">
                                <option value="1">周推荐</option>
                                <option value="2">月推荐</option>
                                <option value="3">攻略推荐</option>
                            </select>
                        </div>
                    </div>


                </form>

            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
                <button type="button" class="btn btn-primary saveBtn">保存</button>
            </div>
        </div>
    </div>
</div>


<div class="container " style="margin-top: 20px">
    <#include "../common/top.ftl">
    <div class="row">
        <div class="col-sm-3">
        <#--设置当前要回显当前菜单,必须在载人菜单前完成设置-->
            <c:set var="menu" value="department"/>
                <#assign menu = "releaseTravel" >
           <#include "../common/menu.ftl">
        </div>
        <div class="col-sm-9">
            <div class="row">
                <div class="col-sm-12">
                    <h1 class="page-head-line">已发布游记管理</h1>
                </div>
            </div>

            <!--高级查询--->
            <form class="form-inline" id="searchForm" action="/travel/releaseList.do" method="post">
                <input type="hidden" id="currentPage" name="currentPage" value="1">
                <div class="form-group">
                    <label>关键字:</label>
                    <input type="text" class="form-control" name="keyword" value="${(qo.keyword)!}"
                           placeholder="请输入标题">
                </div>





                <button type="submit" class="btn btn-primary">
                    <span class="glyphicon glyphicon-search"></span> 查询
                </button>

            </form>

            <table class="table table-striped table-hover">
                <tr>
                    <th>标题</th>
                    <th>封面</th>
                    <th>地点</th>
                    <th>作者</th>
                    <th>发布时间</th>
                    <th>状态</th>
                </tr>
                <!--如果result不为空就迭代输出-->
                    <#if result??>
                        <#list result.list as entity>
                        <tr>
                            <td>${entity.title}</td>
                            <td><img src="${(entity.coverUrl)!}" width="30px"></td>
                            <td>${(entity.place.name)!}</td>
                            <td>${(entity.author.nickName)!}</td>
                            <td>${(entity.releaseTime?string("yyyy-MM-dd"))!}</td>
                            <td>${(entity.stateName)!}</td>

                            <td><a href="javascript:;" class="btn showContent" data-id="${entity.id}" >游记查看</a></td>
                            <td><a href="javascript:;" class="btn stateBtn" data-state="2" data-id="${entity.id}">发布取消</a></td>
                            <td><a href="javascript:;" class="btn commendBtn" data-json='${entity.JSONString}'>推荐</a></td>


                        </tr>
                        </#list>
                    </#if>
            </table>
            <!--分页-->
            <#include "../common/page.ftl">
        </div>
    </div>
</div>


</body>

</html>